package com.zhangbaiyan.test;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author zhangbaiyan
 * @date 2024-09-25 20:19
 * @description:
 * @version:
 */
public class Demo1 {
    public static void main(String[] args) throws UnknownHostException {
      /*
        static InteAddress getByName(String host) 确定主机名称的IP地址。主机名称可以是机器名称,也可以是IP地址
        String getHostName() 获取此IP地址的主机名
        String getHostAddress() 获取此IP地址的字符串格式的文本表示
       */
        //1.获取InetAddress对象
         //IP的对象 一台电脑的对象
        InetAddress address = InetAddress.getByName("river");
        System.out.println(address);

        String name = address.getHostName();
        System.out.println(name);

        String ip = address.getHostAddress();
        System.out.println(ip);
    }
}
